package it.appcatalogobase;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
 
public class ChiSiamoFragment extends Fragment {
	ChiSiamoDataSource dataCS;
	SharedPreferences prefs;

	@Override
	public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        prefs = getActivity().getSharedPreferences("SyncPref", Context.MODE_PRIVATE);
	    }
	
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
 
        View rootView = inflater.inflate(R.layout.fragment_chisiamo, container, false);

       
        return rootView;
    }
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState){
    	super.onActivityCreated(savedInstanceState); 
    	if(!prefs.getBoolean("FirstSync", true)){
	         dataCS = new ChiSiamoDataSource(getActivity());
	         List<ChiSiamo> lista = dataCS.getAllChiSiamo();
	         try {
				String descr = URLDecoder.decode(Html.fromHtml(lista.get(0).getDescr()).toString(), "ISO-8859-1");
				TextView txt = (TextView) getActivity().findViewById(R.id.chisiamo);
				txt.setText(descr);
	         } catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        }else{
        	TextView txt = (TextView) getActivity().findViewById(R.id.chisiamo);
			txt.setText("E' necessario fare almeno una sincronizzazione");
        }
    }
    
}